#!/usr/bin/python

"""calc_blackwhite.py

this script is
"""

__author__ = 'takahiro'
__version__ = '2014-02-10 1.00 (takahiro)'

import sys
import optparse

usage = "%prog [options] [filename]"
parser = optparse.OptionParser( usage=usage )
parser.parse_args( )

if len( sys.argv ) == 1:
  stream = sys.stdin
elif len( sys.argv ) == 2:
  stream = open( sys.argv[ 1 ], 'r' )
else:
  parser.print_help( )
  exit( )

keys = open('format.org', 'r').readlines()[0].rstrip().split(' ')

for line in stream:
  array = line.rstrip().split('\t')
  open_val = int(array[keys.index('open')])
  high_val = int(array[keys.index('high')])
  low_val = int(array[keys.index('low')])
  close_val = int(array[keys.index('close')])

  diff_val = close_val - open_val
  if open_val > close_val:
    upper_shadow = high_val - open_val
    lower_shadow = close_val - low_val
  else:
    upper_shadow = high_val - close_val
    lower_shadow = open_val - low_val
  
  print '%d\t%d\t%d' % (diff_val, upper_shadow, lower_shadow)

